package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.mapper.LoginMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.User;
import com.itheima.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper mapper;

    @Override
    public Result login(User user) {

        if (user==null){
            return new Result(false,"请先输入");
        }
        String password = DigestUtils.md5DigestAsHex(user.getPassword().getBytes());
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getUsername,user.getUsername());
        User user1 = mapper.selectOne(wrapper);
        if (user1 == null){
            return new Result(false,"该账户不存在");
        }
        if (!user1.getPassword().equals(password)){
            return new Result(false,"密码错误");
        }
        return new Result(true,"登录成功",user1);
    }

}
